home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TupleDatabase.h
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __TUPLEDATABASE__
- #define __TUPLEDATABASE__
-
- #ifndef __TYPES__
- #include "Types.h"
- #endif
-
- #ifndef __BUFFER__
- #include "Buffer.h"
- #endif
-
- #ifndef __DATAITEM__
- #include "DataItem.h"
- #endif
-
- #ifndef __COMPARABLE__
- #include "Comparable.h"
- #endif
-
- #ifndef __DIRECTOBJECT__
- #include "DirectObject.h"
- #endif
-
- class ATupleKey;
- class ATupleDatabase;
-
- /*============================================================================
-
- ATupleDatabase is an abstract protocol for a data base which contains
- arbitrary data records (ADataItem) that are retrieved using arbitrary
- keys (ATupleKey). The database also supports the notion that records
- can be retrived by a integer index from 1..CountTuples().
-
- Subclasses must override all pure virtual methods declared in this class.
-
- ----------------------------------------------------------------------------*/
-
- class ATupleDatabase : public TDirectObject
- {
- public:
- virtual ~ATupleDatabase ();
-
- virtual Boolean SetTuple ( const ATupleKey&, const ADataItem& ) = 0;
- virtual Boolean SetTuple ( unsigned long index, const ADataItem& );
-
- virtual Boolean GetTuple ( unsigned long index, ATupleKey&, ADataItem& );
- virtual Boolean GetTupleData ( const ATupleKey&, ADataItem& ) = 0;
- virtual Boolean GetTupleData ( unsigned long index, ADataItem& );
- virtual Boolean GetTupleKey ( unsigned long index, ATupleKey& ) = 0;
- virtual Boolean GetTupleDataSize ( const ATupleKey&, unsigned long& ) = 0;
-
- virtual Boolean DeleteTuple ( const ATupleKey& ) = 0;
-
- virtual Boolean FindIndexOfTuple ( const ATupleKey&, unsigned long& index ) const = 0;
- virtual Boolean DoesTupleExist ( const ATupleKey& ) const = 0;
- virtual unsigned long CountTuples () const = 0;
-
- virtual void Flush ();
-
- virtual ostream& operator >> ( ostream& ) const;
-
- protected: ATupleDatabase ();
- ATupleDatabase ( const ATupleDatabase& );
- ATupleDatabase& operator = ( const ATupleDatabase& );
- };
-
- /*============================================================================
-
- ATupleKey is a class which represents a chunk of data used for a key
- in a tuple database.
-
- Tuple key subclasses MUST NEVER return zero for its data buffer addresses!
- However, it can return a length of zero.
-
- ----------------------------------------------------------------------------*/
-
- class ATupleKey : public AComparable
- {
- public:
-
- virtual ~ATupleKey ();
-
- ATupleKey& operator = ( const ATupleKey& );
-
- virtual const void* GetData () const = 0;
- virtual unsigned long GetLength () const = 0;
-
- virtual unsigned long SetLength ( unsigned long ) = 0;
- virtual unsigned long SetData ( const StringPtr );
- virtual unsigned long SetData ( const char* );
- virtual unsigned long SetData ( const void*, unsigned long );
-
- virtual long Compare ( const AComparable& tupleKeysOnly ) const;
- virtual ostream& operator >> ( ostream& ) const;
-
- protected: ATupleKey ();
- ATupleKey ( const ATupleKey& );
- };
-
- /*============================================================================
-
- CTupleKey is a class which represents a tuple key which can
- accept ANY ATupleKey’s data because is contains an internal buffer
- which can be dynamically resized.
-
- Because this class may allocate buffer space on the heap, it is not
- recommended for general use. Use classes which specifically allocate
- statically-sized buffers within their objects instead (i.e. CStringKey)
- because this approach will be more time and space efficient.
-
- ----------------------------------------------------------------------------*/
-
- class CTupleKey : public ATupleKey
- {
- public: CTupleKey ();
- CTupleKey ( unsigned long length );
- CTupleKey ( const char* );
- CTupleKey ( const StringPtr, Boolean includeLengthByte = false );
- CTupleKey ( const void*, unsigned long );
- CTupleKey ( const ADataItem& );
- CTupleKey ( const ATupleKey& );
- virtual ~CTupleKey ();
-
- virtual const void* GetData () const;
- virtual unsigned long SetLength ( unsigned long );
- virtual unsigned long GetLength () const;
-
- protected: CBuffer fBuffer;
- };
-
- /*============================================================================
-
- CFourByteKey is a statically sized key specifically designed for
- efficiently representing tuple keys which internally use pointers
- or longss as their internal data.
-
- ----------------------------------------------------------------------------*/
-
- class CFourByteKey : public ATupleKey
- {
- public: CFourByteKey ();
- CFourByteKey ( long value );
- CFourByteKey ( unsigned long value );
- CFourByteKey ( const void* value );
- virtual ~CFourByteKey ();
-
- virtual const void* GetData () const;
- virtual unsigned long SetLength ( unsigned long );
- virtual unsigned long GetLength () const;
- virtual long Compare ( const AComparable& tupleKeysOnly ) const;
-
- virtual ostream& operator >> ( ostream& ) const;
-
- private: unsigned long fData;
- };
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- #pragma push
- #pragma segment ATupleDatabase
-
- /***********************************|****************************************/
-
- inline unsigned long
- ATupleKey::SetData ( const StringPtr string )
- {
- return SetData ( string, string [ 0 ] + 1 );
- }
-
- /***********************************|****************************************/
-
- inline ATupleKey&
- ATupleKey::operator = ( const ATupleKey& that )
- {
- SetData ( that.GetData (), that.GetLength () );
- return *this;
- }
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- inline const void*
- CTupleKey::GetData () const
- {
- return fBuffer.GetPhysicalStart ();
- }
-
- /***********************************|****************************************/
-
- inline unsigned long
- CTupleKey::GetLength () const
- {
- return fBuffer.GetPhysicalLength ();
- }
-
- /***********************************|****************************************/
-
- inline unsigned long
- CTupleKey::SetLength ( unsigned long length )
- {
- return fBuffer.SetPhysicalLength ( length );
- }
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- inline unsigned long
- CFourByteKey::GetLength () const
- {
- return sizeof ( fData );
- }
-
- /***********************************|****************************************/
-
- inline const void*
- CFourByteKey::GetData () const
- {
- return &fData;
- }
-
- /***********************************|****************************************/
-
- #pragma pop
-
- #endif // __TUPLEDATABASE__
-
-